n = input()
if n.isdigit() and len(n) == 4:
    n1 = n[0]
    n2 = n[1]
    n3 = n[2]
    n4 = n[3]
    s = []
    count1 = 0
    for i in range(1, 10000):
        if int(n1 + n2) % i == 0:
            count1 += 1
    if count1 == 2:
                s.append(int(n1 + n2))
    count2 = 0
    for i in range(1, 10000):
        if int(n2 + n3) % i == 0:
            count2 += 1
    if count2 == 2:
                s.append(int(n2 + n3))
    count3 = 0
    for i in range(1, 10000):
        if int(n3 + n4) % i == 0:
            count3 += 1
    if count3 == 2:
                s.append(int(n3 + n4))
    count4 = 0
    for i in range(1, 10000):
        if int(n1 + n3) % i == 0:
            count4 += 1
    if count4 == 2:
                s.append(int(n1 + n3))
    count5 = 0
    for i in range(1, 10000):
        if int(n1 + n4) % i == 0:
            count5 += 1
    if count5 == 2:
                s.append(int(n1 + n4))
    count6 = 0
    for i in range(1, 10000):
        if int(n2 + n4) % i == 0:
            count1 += 1
    if count6 == 2:
                s.append(int(n2 + n4))
    count7 = 0
    for i in range(1, 10000):
        if int(n1 + n2 + n3) % i == 0:
            count7 += 1
    if count7 == 2:
        s.append(int(n1 + n2 + n3))
    count8 = 0
    for i in range(1, 10000):
        if int(n2 + n3 + n4) % i == 0:
            count8 += 1
    if count8 == 2:
        s.append(int(n2 + n3 + n4))
    count9 = 0
    for i in range(1, 10000):
        if int(n1 + n2 + n3 + n4) % i == 0:
            count9 += 1
    if count9 == 2:
        s.append(int(n1 + n2 + n3 + n4))
    count10 = 0
    for i in range(1, 10000):
        if int(n1) % i == 0:
            count10 += 1
    if count10 == 2:
        s.append(int(n1))
    count11 = 0
    for i in range(1, 10000):
        if int(n2) % i == 0:
            count11 += 1
    if count11 == 2:
        s.append(int(n2))
    count12 = 0
    for i in range(1, 10000):
        if int(n3) % i == 0:
            count12 += 1
    if count12 == 2:
        s.append(int(n3))
    count13 = 0
    for i in range(1, 10000):
        if int(n4) % i == 0:
            count13 += 1
    if count13 == 2:
        s.append(int(n4))
    if len(s) <= 0:
        print(0)
    else:
        print(max(s))
else:
    print(0)